import { orderRefundDetail, orderRefundRefuse, orderRefundAgree } from '../../../../api.js'
var app = getApp(); //获取App内部的信息
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail:[],
    length:6,
    password_input_focus:false,
    password_box:false,
    password_text:'',
    info_batchcode:'',
    look_picurl:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.batchcode)
    var that = this
    that.setData({
      info_batchcode: options.batchcode
    })
    orderRefundDetail({
      token: app.globalData.token,
      info_batchcode: options.batchcode
    }).then(res =>{
      console.log(res)
      if(res.data.code == 666){
        that.setData({
          detail:res.data.data
        })
        
        for (var i = 0; i < res.data.data.pics.length;i++){
          that.data.look_picurl.push(res.data.data.pics[i].url)
        }
        that.setData({
          look_picurl: that.data.look_picurl
        })
        console.log()
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '赋能奢商，只为业绩增长',
      imageUrl: "https://document.growthupup.com/growthShare.jpg?t=" + new Date().getTime(),
      path: '/pages/user/login/login',
    }
  },
  refuse_btn(){
    var that = this
    wx.showModal({
      title: '提示',
      content: '一经拒绝，不能再次操作',
      cancelColor: '#000',
      confirmColor:'#000',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          orderRefundRefuse({
            token: app.globalData.token,
            info_batchcode: that.data.detail.info_batchcode
          }).then(res => {
            console.log(res)
            if (res.data.code == 666) {
              wx.showToast({
                title: '已拒绝',
                icon:'none'
              })
              setTimeout(function () {
                wx.redirectTo({
                  url: '/pages/user/afterSale/afterSale'
                })
              }, 1500)
            }else{
              wx.showToast({
                title: res.data.msg,
                icon: 'none'
              })
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })    
  },
  agree_btn(){
   var that = this
    if (that.data.detail.is_pay_password == 1){
      that.setData({
        password_box: true,
        password_input_focus: true
      }) 
    }else{
      wx.setStorageSync('payPassword','no')
      wx.showToast({
        title: '请先设置支付密码',
        icon:'none'
      })
      setTimeout(function(){
        wx.navigateTo({
          url: '/pages/user/bill/putForward/newPassword/newPassword'
        })
      },1500)      
    }   
  },
  password_length(e){
    console.log(e.detail.value)
    var that = this
    if (e.detail.value.length > 5){
      that.setData({
        password_text: e.detail.value,
        password_input_focus: false
      })
      return
    }else{
      that.setData({
        password_text: e.detail.value
      })
    }
  },
  input_focus(){
    this.setData({
      password_input_focus: true
    })
  },
  password_none(){
    this.setData({
      password_box:false
    })
  },
  RefundAgree(){
    var that = this
    orderRefundAgree({
      token: app.globalData.token,
      info_batchcode: that.data.detail.info_batchcode,
      pay_password: that.data.password_text
    }).then(res =>{
      console.log(res)
      if(res.data.code == 666){
        wx.showToast({
          title: '退款成功',
        })   
        setTimeout(function(){
          wx.redirectTo({
            url: '/pages/user/afterSale/afterSale'
          })
        },1500)        
      }else{
        wx.showToast({
          title: res.data.msg,
          icon:'none'
        })
      }
      that.setData({
        password_box: false,
        password_text:''
      })
    })
  },
  order_info(){
    wx.navigateTo({
      url: '/pages/orderControl/orderDetail/orderDetail?id=' + this.data.detail.order_info_id,
    })
  },
  look_img(){
    var that = this
    wx.previewImage({
      urls: that.data.look_picurl // 需要预览的图片http链接列表
    })
  }
})